/**
 * Source file: OnBlur_Application_Funeral_Claim.ejs
 * Copyright (C) 2013 : Quantum Solutions
 * Id: $Id: OnBlur_ApplicationForFuneralClaim.ejs 136 2013-05-14 16:35:09Z WillieVisagie55@gmail.com $
 * Date: $Date: 2013-05-14 16:35:09 +0000 (Tue, 14 May 2013) $
 */

var prevField = ""; 
function Field_onBlur(f) {
	prevField = f;
}

function Field_onFocus(f){
	//alert ("Field_onFocus:" + f.name );
	
	// only validate when we change fields
	// (ie can blur a field without leaving it! amazing! no!)
	if (f.name != prevField.name) {
		validateFields(prevField);
	}
}	

function validateFields(f) {
	 //alert("validateFields: "+f.name);

	if(f.name=="MMWA_Code") {
		CheckPostal("MMWA_Sub","MMWA_Code");
    } else if(f.name=="DA_Code") {
		CheckPostal("DA_Sub","DA_Code");
    } else if(f.name=="H_Code") {
		CheckPostal("H_Sub","H_Code");
    } else if(f.name=="TCA_Code") {
		CheckPostal("TCA_Sub","TCA_Code");
    } else if(f.name=="FPA_Code") {
		CheckPostal("FPA_Sub","FPA_Code");
    } else if(f.name=="DDRA_Code") {
		CheckPostal("DDRA_Sub","DDRA_Code");
    } else if(f.name=="DEA_Code") {
		CheckPostal("DEA_Sub","DEA_Code");
    } else if(f.name=="CA_Code") {
		CheckPostal("CA_Sub","CA_Code");
		
    } else if(f.name=="IDnumber") {
		if (!IDNoValidater(EFormGetValue("IDnumber")) && EFormGetValue("IDnumber") != ""){
			alert("Main member IDnumber is invalid: " + EFormGetValue("IDnumber"));				
			EFormSetFocus(EFormGetField("IDnumber"));  
		} 
    } else if(f.name=="DIDnumber" || f.name=="TypeOfIdentification" ) {		
		//alert ( "DIdType="+EFormGetValue("TypeOfIdentification") );
		if (EFormGetValue("DIDnumber") != "" && EFormGetValue("TypeOfIdentification") == "RSAID" && !IDNoValidater(EFormGetValue("DIDnumber"))){
			alert("Deceased ID number is invalid: " + EFormGetValue("DIDnumber"));				
			EFormSetFocus(EFormGetField("DIDnumber"));  
		} else if (EFormGetValue("DIDnumber") != ""  && EFormGetValue("TypeOfIdentification") == "STILLBORN" && !IDNoValidaterStillBorn(EFormGetValue("DIDnumber"))){
			//alert("Still born ID number is invalid: " + EFormGetValue("DIDnumber"));				
			EFormSetFocus(EFormGetField("DIDnumber")); 		
		}
    } else if(f.name=="CIDnumber") {
		if (!IDNoValidater(EFormGetValue("CIDnumber")) && EFormGetValue("CIDnumber") != ""){
			alert("Claimant ID number is invalid: " + EFormGetValue("CIDnumber"));				
			EFormSetFocus(EFormGetField("CIDnumber"));  
		} 
    } else if(f.name=="PDIDnumber") {
		if (!IDNoValidater(EFormGetValue("PDIDnumber")) && EFormGetValue("PDIDnumber") != ""){
			alert("ID number is invalid: " + EFormGetValue("PDIDnumber"));				
			EFormSetFocus(EFormGetField("PDIDnumber"));  
		}
	
	} else if (f.name=="CDDateSigned") {
		if (!CheckDate(EFormGetValue("CDDateSigned")) && EFormGetValue("CDDateSigned") != ""){
			//alert("Invalid date: " + EFormGetValue("CDDateSigned"));
			EFormSetFocus(EFormGetField("CDDateSigned")); 
		}
	} else if (f.name=="Ddod") {
		if (!CheckDate(EFormGetValue("Ddod")) && EFormGetValue("Ddod") != ""){
			//alert("Invalid date: " + EFormGetValue("Ddod"));
			EFormSetFocus(EFormGetField("Ddod")); 
		}	
	} else if (f.name=="PDDate") {
		if (!CheckDate(EFormGetValue("PDDate")) && EFormGetValue("PDDate") != ""){
			//alert("Invalid date: " + EFormGetValue("PDDate"));
			EFormSetFocus(EFormGetField("PDDate")); 
		}
	} else if (f.name=="Dofuneral") {
		if (!CheckDateNoFutureCheck(EFormGetValue("Dofuneral")) && EFormGetValue("Dofuneral") != ""){
			//alert("Invalid date: " + EFormGetValue("Dofuneral"));
			EFormSetFocus(EFormGetField("Dofuneral")); 
		}
	} else if(f.name=="MMTelw") {
		if (!TelNoValidater(EFormGetValue("MMTelw")) && EFormGetValue("MMTelw") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("MMTelw"));				
			EFormSetFocus(EFormGetField("MMTelw"));  
		} 
	} else if(f.name=="MMTelh") {
		if (!TelNoValidater(EFormGetValue("MMTelh")) && EFormGetValue("MMTelh") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("MMTelh"));				
			EFormSetFocus(EFormGetField("MMTelh"));  
		} 
	} else if(f.name=="H_Telw") {
		if (!TelNoValidater(EFormGetValue("H_Telw")) && EFormGetValue("H_Telw") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("H_Telw"));				
			EFormSetFocus(EFormGetField("H_Telw"));  
		} 
	} else if(f.name=="FPTel") {
		if (!TelNoValidater(EFormGetValue("FPTel")) && EFormGetValue("FPTel") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("FPTel"));				
			EFormSetFocus(EFormGetField("FPTel"));  
		} 
	} else if(f.name=="DETel") {
		if (!TelNoValidater(EFormGetValue("DETel")) && EFormGetValue("DETel") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("DETel"));				
			EFormSetFocus(EFormGetField("DETel"));  
		}
	} else if(f.name=="DDRTel") {
		if (!TelNoValidater(EFormGetValue("DDRTel")) && EFormGetValue("DDRTel") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("DDRTel"));				
			EFormSetFocus(EFormGetField("DDRTel"));  
		}
	} else if(f.name=="CCell") {
		if (!TelNoValidater(EFormGetValue("CCell")) && EFormGetValue("CCell") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("CCell"));				
			EFormSetFocus(EFormGetField("CCell"));  
		} 
	} else if(f.name=="CTelw") {
		if (!TelNoValidater(EFormGetValue("CTelw")) && EFormGetValue("CTelw") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("CTelw"));				
			EFormSetFocus(EFormGetField("CTelw"));  
		} 
	} else if(f.name=="PDTel") {
		if (!TelNoValidater(EFormGetValue("PDTel")) && EFormGetValue("PDTel") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("PDTel"));				
			EFormSetFocus(EFormGetField("PDTel"));  
		} 
	} else if(f.name=="PDCellno") {
		if (!TelNoValidater(EFormGetValue("PDCellno")) && EFormGetValue("PDCellno") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("PDCellno"));				
			EFormSetFocus(EFormGetField("PDCellno"));  
		} 
	} else if(f.name=="PDAccNo") {		
		if (EFormGetValue("PDAccNo") != "") {
			AccNoValidatorNew("PDAccNo","PDAccType","PDBranchCode","PDBankCode");
		}
	}
    return true;
}